package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassName: SoilPhEnum
 * @Author: Mario
 * @Date: 2024-08-18 15:04
 * @Description: 土壤酸碱度枚举值
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.enums
 */
@Getter
@AllArgsConstructor
public enum SoilHumidityEnum {

    OVER_WET("过湿", 90, Double.POSITIVE_INFINITY, 60),
    SUITABLE("适宜", 60, 90, 100),
    SLIGHT_DROUGHT("轻度干旱", 50, 60, 80),
    MODERATE_DROUGHT("中度干旱", 40, 50, 40),
    SEVERE_DROUGHT("重度干旱", 30, 40, 20),
    NO("无", 0, 30, 15);

    private final String desc;

    private final double minValue;

    private final double maxValue;

    private final double calculationValue;

    public static double getCalculationValue(double value) {
        return Arrays.stream(values())
                .filter(f -> value >= f.getMinValue() && value < f.getMaxValue())
                .findFirst()
                .map(SoilHumidityEnum::getCalculationValue)
                .orElseThrow(() -> new IllegalArgumentException("Invalid soil humidity value"));
    }
}
